package com.boulderai.mcp.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;

/**
 * MCP协议消息基类
 * 遵循JSON-RPC 2.0规范
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class McpMessage {
    
    @JsonProperty("jsonrpc")
    private String jsonrpc = "2.0";
    
    @JsonProperty("id")
    private Long id;
    
    @JsonProperty("method")
    private String method;
    
    @JsonProperty("params")
    private JsonNode params;
    
    @JsonProperty("result")
    private JsonNode result;
    
    @JsonProperty("error")
    private McpError error;
    
    public McpMessage() {}
    
    public McpMessage(Long id, String method, JsonNode params) {
        this.id = id;
        this.method = method;
        this.params = params;
    }
    
    // Getters and Setters
    public String getJsonrpc() {
        return jsonrpc;
    }
    
    public void setJsonrpc(String jsonrpc) {
        this.jsonrpc = jsonrpc;
    }
    
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getMethod() {
        return method;
    }
    
    public void setMethod(String method) {
        this.method = method;
    }
    
    public JsonNode getParams() {
        return params;
    }
    
    public void setParams(JsonNode params) {
        this.params = params;
    }
    
    public JsonNode getResult() {
        return result;
    }
    
    public void setResult(JsonNode result) {
        this.result = result;
    }
    
    public McpError getError() {
        return error;
    }
    
    public void setError(McpError error) {
        this.error = error;
    }
    
    /**
     * 判断是否为请求消息
     */
    public boolean isRequest() {
        return method != null && result == null && error == null;
    }
    
    /**
     * 判断是否为响应消息
     */
    public boolean isResponse() {
        return method == null && (result != null || error != null);
    }
    
    /**
     * 判断是否为通知消息
     */
    public boolean isNotification() {
        return method != null && id == null;
    }
}